HTTP Server
-
A basic HTTP server. Currently this is implemented using the PoCSocket abstraction, but the intention is to remove this dependency and reimplement the class using transport APIs provided by the Server APIs working group.
See moreDeclaration
Swift
public class HTTPServer: HTTPServing -
Definition of an HTTP server.
See moreDeclaration
Swift
public protocol HTTPServing : class
-
Typealias for a closure that handles an incoming HTTP request The following is an example of an echo
HTTPRequestHandlerthat returns the request it receives as a response:func echo(request: HTTPRequest, response: HTTPResponseWriter ) -> HTTPBodyProcessing { response.writeHeader(status: .ok) return .processBody { (chunk, stop) in switch chunk { case .chunk(let data, let finishedProcessing): response.writeBody(data) { _ in finishedProcessing() } case .end: response.done() default: stop = true response.abort() } } }This then needs to be registered with the server using
HTTPServer.start(port:handler:)Declaration
Swift
public typealias HTTPRequestHandler = (HTTPRequest, HTTPResponseWriter) -> HTTPBodyProcessingParameters
reqthe incoming HTTP request.
resa writer providing functions to create an HTTP reponse to the request.
-
Class protocol containing a
handle()function that implementsHTTPRequestHandlerto respond to incoming HTTP requests.See moreSee
HTTPRequestHandlerfor more informationDeclaration
Swift
public protocol HTTPRequestHandling: class
View on GitHub
HTTP Server Reference